package cn.com.backstage.controller.base;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiU_see_his;

import cn.com.api.service.ApiU_see_hisService;

import cn.com.util.*;


public class U_see_hisBaseController {

	private static Logger logger = Logger.getLogger(U_see_hisBaseController.class);
	
	@Autowired
	private ApiU_see_hisService apiU_see_hisService;
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "u_see_his-list")
	public ModelAndView u_see_his_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_see_his_list.jsp");
		
		List<ApiU_see_his> u_see_hiss = apiU_see_hisService.findU_see_hiss();
		mv.addObject("u_see_hiss", u_see_hiss);
		
		return mv;
	}
	
	/**
	 * 进入新增或者编辑页面
	 * @return
	 */
	@RequestMapping(value = "u_see_his-add-pre")
	public ModelAndView u_see_his_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_see_his_add.jsp");
		//
		if(request.getParameter("id")!=null){
			String id = request.getParameter("id");
			ApiU_see_his u_see_his = apiU_see_hisService.findU_see_hisById(Integer.valueOf(id));
			mv.addObject("u_see_his",u_see_his);
		}
		return mv;
	}

	/**
	 *新增或者编辑
	 * @return
	 */
	@RequestMapping(value = "u_see_his-add")
	public void u_see_his_add(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String id = request.getParameter("id");
		String user_id = request.getParameter("user_id");
		String see_uid = request.getParameter("see_uid");
		String is_read = request.getParameter("is_read");
		String see_time = request.getParameter("see_time");
		String ext1 = request.getParameter("ext1");
		String ext2 = request.getParameter("ext2");
		String ext3 = request.getParameter("ext3");
		
		Map<String,Object> map = new HashMap<String,Object>();
		//String id = request.getParameter("id");
		//add
		if(id==null || (id.trim()).equals("")){
			ApiU_see_his u_see_his = new ApiU_see_his();
            /*
		    u_see_his.setId(id);
		    u_see_his.setUser_id(user_id);
		    u_see_his.setSee_uid(see_uid);
		    u_see_his.setIs_read(is_read);
		    u_see_his.setSee_time(see_time);
		    u_see_his.setExt1(ext1);
		    u_see_his.setExt2(ext2);
		    u_see_his.setExt3(ext3);
	        */
			apiU_see_hisService.insertU_see_his(u_see_his);
		}
		//edit
		else{
			ApiU_see_his u_see_his = apiU_see_hisService.findU_see_hisById(Integer.valueOf(id));
	        /*
		    u_see_his.setId(id);
		    u_see_his.setUser_id(user_id);
		    u_see_his.setSee_uid(see_uid);
		    u_see_his.setIs_read(is_read);
		    u_see_his.setSee_time(see_time);
		    u_see_his.setExt1(ext1);
		    u_see_his.setExt2(ext2);
		    u_see_his.setExt3(ext3);
			*/
			apiU_see_hisService.updateU_see_his(u_see_his);
		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
        JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
	/**
	 *删除
	 * @return
	 */
	@RequestMapping(value = "u_see_his-delete")
	public void u_see_his_delete(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		
		//delete
		int ret_i =	apiU_see_hisService.deleteU_see_his(Integer.valueOf(id));
		
		//
		if(ret_i > 0){
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
}



